package com.zh.rxharmony.sample.util;

import com.zh.rxharmony.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Context;

public class ToastUtil {
    private ToastUtil() {
    }

    /**
     * Toast
     */
    public static void toast(Context context,String msg) {
        context = context.getApplicationContext();
        Component toastLayout = LayoutScatter.getInstance(context)
                .parse(ResourceTable.Layout_layout_toast, null, false);
        new ToastDialog(context)
                .setAlignment(LayoutAlignment.CENTER)
                .setSize(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT)
                .setComponent(toastLayout)
                .setText(msg)
                .show();
    }
}